package com.dao;

import com.db.BaseDao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TeacherDao {
    Connection con = null;
    Statement stm = null;
    ResultSet rst = null;

    public List<Map> query(){
        List<Map> list  = new ArrayList<>();
         // 1 获取数据库连接
         con =  BaseDao.getCon();
        try {//创建可以执行sql的对象
             stm = con.createStatement();
             //利用stm对象去执行查询的sql
             rst = stm.executeQuery("select * from teacher");
             while (rst.next()){//遍历查询的结果
                Integer id =  rst.getInt("id");
                String tname = rst.getString("tname");
                String zhicheng = rst.getString("zhicheng");
                Map map = new HashMap();
                 map.put("id",id);
                 map.put("tname",tname);
                 map.put("zhicheng",zhicheng);
                 list.add(map);
             }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return  list;
    }
}
